package bintree.leetcode;

//543. 二叉树的直径

public class Num543_diameterOfBinaryTree {
    private int max=0;
    public int diameterOfBinaryTree(TreeNode root) {
        if(root==null || root.left==null && root.right==null){
            return 0;
        }
        height(root);
        return max;
    }
    private int height(TreeNode root){
        if(root==null){
            return 0;
        }
        int L=height(root.left);
        int R=height(root.right);
        max=Math.max(max,L+R);
        return 1+Math.max(L,R);
    }
}
